﻿@{
    Layout = null;
}
@using AutoSchedule.Dtos.Models;
@model DataSource;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/css/layui.css" rel="stylesheet" />
</head>
<body>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>数据源修改表单</legend>
    </fieldset>

    <form class="layui-form">

        <div class="layui-form-item" hidden="hidden">
            <label class="layui-form-label">guid</label>
            <div class="layui-input-block">
                <input type="text" name="GUID" lay-verify="required" autocomplete="off" class="layui-input" value="@Model.GUID">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单据名称</label>
            <div class="layui-input-block">
                <input type="text" name="Name" lay-verify="required" autocomplete="off" placeholder="请输入单据名称" class="layui-input" value="@Model.Name">
            </div>
        </div>

        <div class="layui-form-item" pane="">
            <label class="layui-form-label">是否启用</label>
            @if (@Model.IsStart == "1")
            {
                <div class="layui-input-block">
                    <input type="checkbox" checked="" lay-verify="required" name="IsStart" lay-skin="switch" lay-filter="switchTest" title="是否启用">
                </div>
            }
            else
            {
                <div class="layui-input-block">
                    <input type="checkbox" lay-verify="required" name="IsStart" lay-skin="switch" lay-filter="switchTest" title="是否启用">
                </div>
            }

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">主关键字段</label>
            <div class="layui-input-block">
                <input type="text" name="MainKey" lay-verify="required" autocomplete="off" placeholder="请输入单据名称" class="layui-input" value="@Model.MainKey">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">分组数据源</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" lay-verify="required" class="layui-textarea" name="GroupSqlString">@Model.GroupSqlString</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">业务选择数据源</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="SqlString">@Model.SqlString</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">调用正常后执行语句</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="AfterSqlString">@Model.AfterSqlString</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">调用异常后执行语句</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="AfterSqlstring2">@Model.AfterSqlstring2</textarea>
            </div>
        </div>
        @*<div class="layui-form-item layui-form-text">
                <label class="layui-form-label">编辑器</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
                </div>
            </div>*@
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="enSure">提交</button>
                <button type="reset" class="layui-btn" onclick="formClose()">取消</button>
            </div>
        </div>
    </form>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui.js"></script>
    <script src="~/js/bank.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //创建一个编辑器
            //var editIndex = layedit.build('LAY_demo_editor');

            ////监听指定开关
            form.on('switch(switchTest)', function (data) {
                layer.msg('启用状态：' + (this.checked ? '是' : '否'), {
                    offset: '6px'
                });
            });

            //console.log(layui.table.cache.tablename);

            form.on('submit(enSure)', function (data) {
                var dataDetail = JSON.stringify(data.field);
                console.log(dataDetail);
                $.ajax({
                    url: "/DataSource/DataSourceEdit",
                    async: true,
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    data: dataDetail,
                    success: function (dataResult) {
                        if (dataResult.code != "0") {
                            alert(dataResult.msg);
                        }
                        var index = parent.layer.getFrameIndex(window.name);
                        setTimeout(function () { parent.layer.close(index) }, 1000);
                        setTimeout(function () { parent.location.reload() }, 100);
                    }
                });
                // window.parent.location.reload();

            });

        });
    </script>
</body>
</html>